package cn.com.response;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "ChineseServlet", value = "/ChineseServlet")
public class ChineseServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //第一种解决方式：
        //设置HttpServletResponse使用utf-8编码
//        response.setCharacterEncoding("utf-8");
        //通知浏览器使用utf-8解码
//        response.setHeader("Content-Type","text/html;charset=utf-8");

        //第二种解决方式：
        response.setContentType("text/html;charset=utf-8");
        //解决中文输出乱码问题
        String data="中国广东广州";
        PrintWriter out = response.getWriter();
        out.print(data);

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
